login = window.login ||{
	focus:function(id){
		$('#'+id).focus();
	},
	alert:function(msg){
		alert(msg);
	},
	innerHtml:function(msg){
		$('.loginwrg').html(msg);
		$('.loginwrg').show();
	}
}

$(document).ready(function(){
	$('.tip').click(function(){
		$('.tip').hide();$('#tbUserAccount').focus();
    });
	$('#tbUserAccount').keydown(function(){
    	$('.tip').hide();
    });
	$('#tbUserAccount').focus(function(){
 
    }).blur(function(){
    	var userAccount = $.trim($(this).val());
    	var regMail = /^\w+([-\.]\w+)*@\w+([\.-]\w+)*\.\w{2,4}$/;
    	var regInt = /^-?[1-9]+[0-9]*$/;
    	if (!regMail.exec(userAccount) && !regInt.exec(userAccount)){
    		//$(this).val('');$('.tip').show();
    	}	
    });
	$('.loginbtn').click(function (){chkLogin();});
});


$(document).keypress(function(e) 
{
	if (e.which == 13)chkLogin();
	
});
var isSubmit = false;
function chkLogin(){
	if(isSubmit){
		//login.alert('正在反应，请稍后！');
		//return false;	
	}
	isSubmit = true;
	var userAccount = document.getElementById("tbUserAccount").value;
	var userPwd = document.getElementById("tbUserPwd").value;
	//var code = document.getElementById("tbCode").value;
	if(userAccount==""){
		login.innerHtml('请输入正确的账号！');
		$('.loginwrg').css('right','-118px');
		login.focus("tbUserAccount");
		isSubmit = false;
		return false;
	}
	if(userPwd.length < 5){
		login.innerHtml('对不起，您输入的密码格式错误！');
		$('.loginwrg').css('right','-188px');
		login.focus('tbUserPwd');
		isSubmit = false;
		return false;
	}
	/*
	if(code==""){
		login.alert('请输入验证码');
		login.focus("tbCode");
		isSubmit = false;
		return false;
	}*/
	
	if(isSubmit){
		$('#jxy_login').html("提交中...");$('#jxy_login').attr("id","loading");
		var relink = $('#relink').val();
		$.ajax({
			type: "POST",
			url: 'index.php?m=Member&c=Index&a=login',
			dataType: "json",
			data : "username="+userAccount+"&password="+userPwd+"&isChkCode=0"+"&relink="+relink+"&key="+Math.random(),
			success: function(result){
				if(result){
					if(result == 1){
						window.location.href = relink;
					}else{
						window.location.href = 'index.php';
					}
					
				}else{
					if(result=='303') $('.loginwrg').css('right','-94px');
					else if(result=='304') $('.loginwrg').css('right','-225px');
					else if(result=='305') $('.loginwrg').css('right','-194px');
					login.innerHtml(msg);
					isSubmit = false;
				}
				$('#loading').html("登&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;录");$('#loading').attr("id","jxy_login");
			}
		})
	}
}